package com.huilian.iotbox.admin.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huilian.iotbox.admin.dao.StmtResultDao;
import com.huilian.iotbox.admin.service.FileService;
import com.huilian.iotbox.admin.service.MerchantService;
import com.huilian.iotbox.admin.service.StatsMerchantService;
import com.huilian.iotbox.admin.service.StmtResultService;
import com.huilian.iotbox.data.common.RedisKey;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.config.AgencyConfig;
import com.huilian.iotbox.data.config.MiddlewareConfig;
import com.huilian.iotbox.data.dto.SettleResultDto;
import com.huilian.iotbox.data.dto.StmtResultDto;
import com.huilian.iotbox.data.enums.FunctionEnum;
import com.huilian.iotbox.data.enums.PayCompanyEnum;
import com.huilian.iotbox.data.enums.RequestStatus;
import com.huilian.iotbox.data.enums.RoleEnum;
import com.huilian.iotbox.data.po.StatsMerchant;
import com.huilian.iotbox.data.po.StmtPayFail;
import com.huilian.iotbox.data.po.StmtResult;
import com.huilian.iotbox.data.properties.ConfigProperties;
import com.huilian.iotbox.data.properties.FileProperties;
import com.huilian.iotbox.data.utils.DateTimeUtils;
import com.huilian.iotbox.data.utils.HttpUtils;
import com.huilian.iotbox.data.utils.HttpsMain;
import com.huilian.iotbox.data.utils.SciCalUtils;
import com.huilian.iotbox.data.vo.MerchantVo;
import com.huilian.iotbox.data.vo.StmtResultVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Font;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * @author 谢洛涛
 * @date 2021/6/24 20:12
 */
@Service
@Slf4j
public class StmtResultServiceImpl implements StmtResultService {
    @Autowired
    private StmtResultDao stmtResultDao;
    @Autowired
    private FileProperties fileProperties;
    @Autowired
    private MerchantService merchantService;
    @Autowired
    private ConfigProperties configProperties;
    @Autowired
    private StatsMerchantService statsMerchantService;
    @Autowired
    private RedisTemplate<String, Serializable> redisCacheTemplate;
    @Autowired
    private AgencyConfig agencyConfig;
    @Autowired
    private FileService fileService;

    @Override
    public void mchDayCloseQuery() {

        final String dateStr = DateTimeUtils.getYesterday();
        List<StatsMerchant> statsMerchantList = statsMerchantService.findStatsMerchantList(dateStr);
        String today = DateTimeUtils.convert(LocalDate.now(), DateTimeUtils.LONG_DATE_FORMATTER);
        String yesterday = DateTimeUtils.convert(LocalDate.now().minusDays(1), DateTimeUtils.LONG_DATE_FORMATTER);
        for (StatsMerchant statsMerchant : statsMerchantList) {
            try {
                Map<String, Object> form = new HashMap<>();
                form.put("HlMerchantId", statsMerchant.getMerchantId());
                form.put("SettleDate", today);
                String param = HttpUtils.format(agencyConfig, form, FunctionEnum.MERCHANT_PAYRESULT_QUERY, statsMerchant.getPayCompanyCode());
                String response = HttpsMain.httpsReq(MiddlewareConfig.Merchant, param);
                final Map<String, Object> result = HttpUtils.getResultData(response);
                if (RequestStatus.SUCCESS.getCode().equals(result.get("status")) && RequestStatus.SUCCESS_CODE.getCode().equals(result.get("code"))) {
                    Map<String, Object> resMap = (Map<String, Object>) result.get("data");
                    StmtResult stmtResult = new StmtResult();
//                    stmtResult.setStatsAmt(statsAmt);
                    stmtResult.setStmtDate(yesterday);
                    //获得应打款日期 20200923
                    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                    stmtResult.setPayDate(sdf2.format(sdf.parse(today)));
                    if ("查无记录".equals(result.get("msg")) || "接口访问太频繁".equals(result.get("msg"))) {
                        stmtResult.setPayStatus(0);
                        stmtResult.setStmtStatus(0);
                        stmtResult.setPayFailedReason((String) result.get("msg"));
//                        查询没记录
                        this.handleStmtResult(stmtResult, statsMerchant, yesterday, today);
                    } else {
                        JSONArray list = JSONArray.parseArray(JSON.toJSONString(resMap.get("settleRecordList")));
                        for (int i = 0; i < list.size(); i++) {
                            JSONObject json = list.getJSONObject(i);
                            //orderStatus  INIT已接收  DOING处理中  DONE成功
                            if (json.get("orderStatus").equals("DONE")) {
                                stmtResult.setPayStatus(1);
                                stmtResult.setStmtStatus(1);
                                stmtResult.setPayTime(json.getString("settleDate"));
                            } else if (json.get("orderStatus").equals("INIT") || json.get("orderStatus").equals("DOING")) {
                                stmtResult.setPayStatus(0);
                                stmtResult.setStmtStatus(0);
                            } else if (json.get("orderStatus").equals("FAILED") || json.get("orderStatus").equals("MANUAL")) {
                                stmtResult.setPayStatus(2);     //打款状态  0：未打款 1：打款成功 2：打款失败 3：取消打款
                                stmtResult.setStmtStatus(0);    //结算状态  0:未结算 1：完成
                            }
                            if (!json.get("reason").equals("")) {
                                stmtResult.setPayFailedReason((String) json.get("reason"));
                                stmtResult.setPayStatus(2);
                            }
                            if (!json.get("settleFee").equals("")) {
                                stmtResult.setSettleFee(new BigDecimal(SciCalUtils.sciCal(
                                        Double.parseDouble(json.getString("settleFee")) / 100, 2)));
                            } else {
                                stmtResult.setSettleFee(BigDecimal.ZERO);
                            }
                            stmtResult.setStmtAmt(new BigDecimal(SciCalUtils.sciCal(
                                    Double.parseDouble(json.getString("settlementAmount")) / 100, 2)));
                            this.handleStmtResult(stmtResult, statsMerchant, yesterday, today);
                        }
                    }
                    if (PayCompanyEnum.YEAHKA.getCode().equals(statsMerchant.getPayCompanyCode())) {
                        //乐刷限制20秒内请求次数不能超过60次
                        Thread.sleep(500);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error("结算查询异常: ", e);
            }
        }
    }

    private void handleStmtResult(StmtResult stmtResult, StatsMerchant statsMerchant, String yesterday, String today) {
        //把部分银行卡号设**
        stmtResult.setStmtDate(yesterday);
        stmtResult.setUserId(statsMerchant.getUserId());
        stmtResult.setPayCompanyCode(statsMerchant.getPayCompanyCode());
        stmtResult.setMerchantId(statsMerchant.getMerchantId());
        stmtResult.setStatsAmt(statsMerchant.getSettlementMoney());
        stmtResult.setRealTotalAmount(statsMerchant.getRealTotalAmount());
        stmtResult.setHandlingCharge(statsMerchant.getHandlingCharge());
        stmtResult.setPayeeAstAcctNo(statsMerchant.getPayeeAstAcctNo());
        stmtResult.setPayeeAstAcctName(statsMerchant.getPayeeAstAcctName());
        stmtResultDao.insert(stmtResult);
        if (stmtResult.getPayStatus() != 1) {
            //打款失败，插入redis中
            StmtPayFail stmtPayFail = new StmtPayFail();
            stmtPayFail.setMerchantId(statsMerchant.getMerchantId());
            stmtPayFail.setPayCompanyCode(statsMerchant.getPayCompanyCode());
            stmtPayFail.setTradeDate(today);
            stmtPayFail.setId(stmtResult.getId());
            final String key = String.format(RedisKey.STMT_PAY_FAIL, stmtPayFail.getMerchantId(), stmtPayFail.getId());
            redisCacheTemplate.opsForValue().set(key, stmtPayFail, 30, TimeUnit.DAYS);
        }
    }

    @Override
    public void mchFailQuery() {
        Set<String> keys = redisCacheTemplate.keys(RedisKey.STMT_PAY_FAIL_BASE + "*");
        log.info("-----------------轮询打款失败查询-开始：{}-------------------", keys.size());
        StmtPayFail item = null;
        for (String key : keys) {
            item = (StmtPayFail) redisCacheTemplate.opsForValue().get(key);
            try {
                boolean flag = this.stmtHelibaoResult(item);
                if (flag) {
                    redisCacheTemplate.delete(key);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public PageInfo<StmtResultVo> findStmtResultDto(StmtResultDto stmtResultDto) {
        PageHelper.startPage(stmtResultDto.getPageNum(), stmtResultDto.getPageSize(), "sr.stmtDate desc");
        List<StmtResultVo> stmtResultVoList = stmtResultDao.findStmtResultDto(stmtResultDto);
        return new PageInfo<>(stmtResultVoList);
    }

    @Override
    public ServerResponse exportTheOrder(StmtResultDto stmtResultDto) {

        // 定义日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); // 设置时区为东八区
        String startDate = sdf.format(stmtResultDto.getCreateTime());
        String endDate = sdf.format(stmtResultDto.getUpdateTime());
        List<StmtResultVo> list = stmtResultDao.findStmtResultDto(stmtResultDto);
        String[] headers;
        if (stmtResultDto.getUserInfo().getRoleId().compareTo(RoleEnum.SUPER_ADMINISTRATOR.getRoleId()) == 0) {
            headers = new String[]{"商户号", "实际结算额", "营业额", "手续费", "节假日结算手续费（万分之二，2024年7月1号起才有数据）", "交易时间", "打款时间", "结算人", "结算卡号", "运营商", "平台统计结算额"};
        } else {
            headers = new String[]{"商户号", "实际结算额", "营业额", "手续费", "节假日结算手续费（万分之二，2024年7月1号起才有数据）", "交易时间", "打款时间", "结算人", "结算卡号", "运营商"};
        }
        String sheetName = "结算订单" + startDate + "至" + endDate;
        // 创建了一个excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet(sheetName);
        sheet.setDefaultColumnWidth(12);
        sheet.setColumnWidth(0, 10 * 256);
        sheet.setColumnWidth(1, 25 * 256);
        sheet.setColumnWidth(2, 26 * 256);
        sheet.setColumnWidth(4, 30 * 256);
        sheet.setColumnWidth(10, 30 * 256);
        sheet.createFreezePane(0, 4, 0, 4);
        //标题样式
        HSSFCellStyle titleStyle = wb.createCellStyle(); // 样式对象
        //设置标题字体格式
        Font font = wb.createFont();
        //设置字体样式
        //font.setFontHeightInPoints((short) 20);   //--->设置字体大小
        font.setFontName("Courier New");   //---》设置字体，是什么类型例如：宋体
        font.setItalic(true);     //--->设置是否是加粗
        titleStyle.setFont(font);     //--->将字体格式加入到style1中
        titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平
        titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); //垂直


        //内容样式
        HSSFCellStyle contextStyle = wb.createCellStyle(); // 样式对象
        //设置标题字体格式
        Font contextfont = wb.createFont();
        contextfont.setFontHeightInPoints((short) 13);   //--->设置字体大小
        //设置字体样式
        contextStyle.setFont(contextfont);     //--->将字体格式加入到style1中
        contextStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平
        contextStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); //垂直
        contextStyle.setWrapText(true);//设置自动换行

        //表格第一行
        HSSFRow row1 = sheet.createRow(0);   //--->创建一行
        row1.setHeightInPoints(20);
        HSSFCell cell1 = row1.createCell(0);   //--->创建一个单元格
        // cell1.setCellStyle(titleStyle);
        cell1.setCellValue("交易记录明细查询");
        //表格第二行
        HSSFRow r2 = sheet.createRow(1);
        r2.setHeightInPoints(20);
        HSSFCell c2 = r2.createCell(0);

        c2.setCellValue("起始时间：[" + startDate + "]  " + "  终止时间：[" + endDate + "]");
        //表格第三行
        HSSFRow r3 = sheet.createRow(2);
        r3.setHeightInPoints(20);
        HSSFCell c3 = r3.createCell(0);
        //c3.setCellValue("合计：" + "   交易总金额:" + statistic.getTradingTotal() + "   交易总笔数:" + statistic.getStrokeCount() + "   应结算总金额:" + statistic.getSettlementTotal() + "   已结算总金额:" + statistic.getStmtTotal() + "   手续费:" + statistic.getHandlingCharge());

        //标题
        HSSFRow row2 = sheet.createRow(3);           //--->创建一行
        contextStyle.setFillForegroundColor(HSSFColor.LEMON_CHIFFON.index);// 设置背景色
        contextStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        contextStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
        contextStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
        contextStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
        contextStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
        contextfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
        contextStyle.setFont(contextfont);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell2 = row2.createCell(i);
            cell2.setCellValue(headers[i]);
            cell2.setCellStyle(contextStyle);
        }
        int index = 0;//记录额外创建的sheet数量
        int j = 0;
        // 循环每行
        for (int i = 4; i < list.size() + 4; i++) {
            if ((i) % 65500 == 0) {
                sheet = wb.createSheet("order" + index);
                index++;
            }
            HSSFRow row = sheet.createRow((i) - (index * 65500));
            // 创建列
            HSSFCell contextCell1 = row.createCell(0);
            // 写入内容
            contextCell1.setCellValue(list.get(j).getMerchantId());

            //实际结算额
            HSSFCell contextCell2 = row.createCell(1);
            if (list.get(j).getStmtAmt() != null) {
                contextCell2.setCellValue(list.get(j).getStmtAmt().toString());
            } else {
                contextCell2.setCellValue(BigDecimal.ZERO.toString());
            }
            //营业额
            HSSFCell contextCell3 = row.createCell(2);
            if (list.get(j).getStmtAmt() != null) {
                contextCell3.setCellValue(list.get(j).getRealTotalAmount().toString());
            } else {
                contextCell3.setCellValue(BigDecimal.ZERO.toString());
            }
            //手续费
            HSSFCell contextCell4 = row.createCell(3);
            if (list.get(j).getStmtAmt() != null) {
                contextCell4.setCellValue(list.get(j).getHandlingCharge().toString());
            } else {
                contextCell4.setCellValue(BigDecimal.ZERO.toString());
            }

            //节假日结算手续费（万分之二）
            HSSFCell contextCell33 = row.createCell(4);
            if (list.get(j).getSettleFee() != null) {
                contextCell33.setCellValue(list.get(j).getSettleFee().toString());
            } else {
                contextCell33.setCellValue(BigDecimal.ZERO.toString());
            }
            //交易时间
            HSSFCell contextCell5 = row.createCell(5);
            contextCell5.setCellValue(list.get(j).getStmtDate());
            //打款时间
            HSSFCell contextCell6 = row.createCell(6);
            contextCell6.setCellValue(list.get(j).getPayTime());
            //结算人
            HSSFCell contextCell7 = row.createCell(7);
            contextCell7.setCellValue(list.get(j).getPayeeAstAcctName());
            //结算卡号
            HSSFCell contextCell8 = row.createCell(8);
            contextCell8.setCellValue(list.get(j).getPayeeAstAcctNo());

            //运营商
            String userName = "";
            HSSFCell contextCell9 = row.createCell(9);
            if (!StringUtils.isEmpty(list.get(j).getOperatorName())) {
                userName = list.get(j).getOperatorName() + ":";
                contextCell9.setCellValue(list.get(j).getOperatorName());
            } else {
                contextCell9.setCellValue("");
            }
            if (!StringUtils.isEmpty(list.get(j).getUsername())) {
                contextCell9.setCellValue(userName + list.get(j).getUsername());
            }

            if (stmtResultDto.getUserInfo().getRoleId().compareTo(RoleEnum.SUPER_ADMINISTRATOR.getRoleId()) == 0) {
                //平台统计结算额
                HSSFCell contextCell10 = row.createCell(10);
                if (list.get(j).getStatsAmt() != null) {
                    contextCell10.setCellValue(list.get(j).getStatsAmt().toString());
                } else {
                    contextCell10.setCellValue(BigDecimal.ZERO.toString());
                }
            }

            j++;
            if (j >= list.size()) {
                j = 0;
            }
        }
        // 保存文件
        FileOutputStream fileOut = null;
        try {
            String fileName = fileService.getFileUrl() + "/" + sheetName + ".xls";

            File f = new File(fileName);
            if (!f.exists()) {
                f.createNewFile();
            }
            // 文件保存的地址和名称
            log.info("------------------------------结算订单导出url:" + fileName);
            fileOut = new FileOutputStream(fileName);
            wb.write(fileOut);
        } catch (IOException e) {
            // 处理文件操作可能发生的IO异常
            e.printStackTrace();
            return ServerResponse.createByErrorMessage("文件保存失败:" + e + fileProperties.getSaveImgPath());
        } catch (Exception e) {
            // 其他异常
            e.printStackTrace();
            return ServerResponse.createByErrorMessage("文件保存过程中发生了错误:" + e);

        } finally {
            // 关闭流
            if (fileOut != null) {
                try {
                    fileOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
//            return ServerResponse.createBySuccess(sheetName + ".xls");


        Map<String, String> map = new HashMap<>();
        map.put("fileName", sheetName + ".xls");
        map.put("downloadUrl", configProperties.getAdminBackEndUrl() + "/api/fileExport/download/" + sheetName + ".xls");
        return ServerResponse.createBySuccess(map);
    }

    private Boolean stmtHelibaoResult(StmtPayFail stmtPayFail) {
        Boolean flag = null;
        try {
            MerchantVo merchantVo = new MerchantVo();
            merchantVo = merchantService.findMerchantByMerchantId(stmtPayFail.getMerchantId());
            Map<String, Object> form = new HashMap<>();
            form.put("HlMerchantId", stmtPayFail.getMerchantId());
            form.put("SettleDate", stmtPayFail.getTradeDate());
            String param = HttpUtils.format(agencyConfig, form, FunctionEnum.MERCHANT_PAYRESULT_QUERY, stmtPayFail.getPayCompanyCode());
            String response = HttpsMain.httpsReq(MiddlewareConfig.Merchant, param);
            final Map<String, Object> result = HttpUtils.getResultData(response);
            StmtResult stmtResult = new StmtResult();
            if (RequestStatus.SUCCESS.getCode().equals(result.get("status")) && RequestStatus.SUCCESS_CODE.getCode().equals(result.get("code"))) {
                if (!"查无记录".equals(result.get("msg"))) {
                    Object data = result.get("data");
                    Map entity = (Map) data;
                    JSONArray list = JSONArray.parseArray(JSON.toJSONString(entity.get("settleRecordList")));
                    for (int i = 0; i < list.size(); i++) {
                        JSONObject json = list.getJSONObject(i);
                        if (json.get("orderStatus").equals("DONE")) {
                            stmtResult.setPayStatus(1);
                            stmtResult.setStmtStatus(1);
                            flag = true;
                        } else if (json.get("orderStatus").equals("INIT") || json.get("orderStatus").equals("DOING")) {
                            stmtResult.setPayStatus(0);
                            stmtResult.setStmtStatus(0);
                        } else if (json.get("orderStatus").equals("FAILED") || json.get("orderStatus").equals("MANUAL")) {
                            stmtResult.setPayStatus(2);     //打款状态  0：未打款 1：打款成功 2：打款失败 3：取消打款
                            stmtResult.setStmtStatus(0);    //结算状态  0:未结算 1：完成
                        }
                        if (!json.get("reason").equals("")) {
                            stmtResult.setPayFailedReason((String) json.get("reason"));
                            stmtResult.setPayStatus(2);
                        }
                        stmtResult.setId(stmtPayFail.getId());
                        stmtResult.setPayeeAstAcctName(merchantVo.getBankCertName());
                        stmtResult.setPayeeAstAcctNo(merchantVo.getBankCardNo());
                        stmtResultDao.updateStmtFail(stmtResult);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    public static void main(String[] args) {

        Map<String, Object> result = new HashMap<>();
        result.put("code", "0000");
        result.put("msg", "Success");
        result.put("sign", "RNg2OIudshddvAL3AMge8OYuHoORTJfvu");
        result.put("status", "S");
        result.put("timestamp", "1683178402121");
        Map<String, Object> data = new HashMap<>();
        data.put("hlMerchantId", "122390897210001");


        List<JSONObject> jsonObjectList = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();

        jsonObject.put("settleFee", "");
        jsonObject.put("reason", "");
        jsonObject.put("merchantId", "5959019742");
        jsonObject.put("orderId", "20220905000159910642");
        jsonObject.put("orderStatus", "DONE");
        jsonObject.put("settleDate", "20220905");
        jsonObject.put("settlementAmount", 11631.00);
        jsonObject.put("settleType", "D1");
        jsonObjectList.add(jsonObject);

        data.put("settleRecordList", jsonObjectList);
        result.put("data", data);
        Map<String, Object> map = new HashMap<>();
        map.put("map", result);
        System.out.println(result.get("map"));

        StmtResult stmtResult = new StmtResult();
        Boolean flag = null;
        if (RequestStatus.SUCCESS.getCode().equals(result.get("status")) && RequestStatus.SUCCESS_CODE.getCode().equals(result.get("code"))) {
            if (!"查无记录".equals(result.get("msg"))) {
                Object dat = result.get("data");
                Map entity = (Map) dat;
                JSONArray list = JSONArray.parseArray(JSON.toJSONString(entity.get("settleRecordList")));
                log.info("list长度--->" + list.size());
                System.out.println("数据详情--->" + list);
                for (int i = 0; i < list.size(); i++) {
                    JSONObject json = list.getJSONObject(i);
                    if (json.get("orderStatus").equals("DONE")) {
                        stmtResult.setPayStatus(1);
                        stmtResult.setStmtStatus(1);
                        flag = true;
                    } else if (json.get("orderStatus").equals("INIT") || json.get("orderStatus").equals("DOING")) {
                        stmtResult.setPayStatus(0);
                        stmtResult.setStmtStatus(0);
                    } else if (json.get("orderStatus").equals("FAILED") || json.get("orderStatus").equals("MANUAL")) {
                        stmtResult.setPayStatus(2);     //打款状态  0：未打款 1：打款成功 2：打款失败 3：取消打款
                        stmtResult.setStmtStatus(0);    //结算状态  0:未结算 1：完成
                    }
                    if (!json.get("reason").equals("")) {
                        stmtResult.setPayFailedReason((String) json.get("reason"));
                        stmtResult.setPayStatus(2);
                    }
                }
                log.info("stmtResult--->" + stmtResult);
            }
        }
    }
}

